package edu.sdufe.copy;

import java.lang.reflect.Array;
import java.util.Arrays;

/**
 * @author wang'ji'cheng
 * @date 2025/6/29
 */

public class Student implements Cloneable {

    private String name;
    private int age;
    private String [] hobby;

    public Student() {
    }


    public Student(String name, int age, String[] hobby) {
        this.name = name;
        this.age = age;
        this.hobby = hobby;
    }

    /**
     * 获取
     * @return name
     */
    public String getName() {
        return name;
    }

    /**
     * 设置
     * @param name
     */
    public void setName(String name) {
        this.name = name;
    }

    /**
     * 获取
     * @return age
     */
    public int getAge() {
        return age;
    }

    /**
     * 设置
     * @param age
     */
    public void setAge(int age) {
        this.age = age;
    }

    /**
     * 获取
     * @return hobby
     */
    public String[] getHobby() {
        return hobby;
    }

    /**
     * 设置
     * @param hobby
     */
    public void setHobby(String[] hobby) {
        this.hobby = hobby;
    }

    public String toString() {
        return "Student{name = " + name + ", age = " + age + ", hobby = " + Arrays.toString(hobby) + "}";
    }
    @Override
    public Student clone() {
        try {
            Student clone = (Student) super.clone();
            // TODO: 复制此处的可变状态，这样此克隆就不能更改初始克隆的内部项
            return clone;
        } catch (CloneNotSupportedException e) {
            throw new AssertionError();
        }
    }
    // 深拷贝实现（对于基本类型，浅拷贝和深拷贝效果相同）
    public Student deepClone() {
        String[] newHobby = Arrays.copyOf(this.hobby, this.hobby.length);
        Student student = this.clone();
        student.hobby=newHobby;
        return student;
    }
}
